#include "RingQueue.hpp"
// #include "Tasks.hpp"
#include <iostream>

void *ProductorRoutine(void *args)
{
    RingQueue<int> *rq = static_cast<RingQueue<int> *>(args);
    while (true)
    {
        int data = rand() % 10 + 1;
        rq->Push(data);
        std::cout << "生产者投递数据：" << data << std::endl;
    }
}
void *ConsumerRoutine(void *args)
{
    RingQueue<int> *rq = static_cast<RingQueue<int> *>(args);
    while (true)
    {
        int data = 0;
        rq->Pop(&data);
        std::cout << "消费者消费数据：" << data << std::endl;
        sleep(1);
    }
}

void test1()
{
    RingQueue<int> *rq = new RingQueue<int>();
    pthread_t p, c;
    pthread_create(&p, nullptr, ProductorRoutine, rq);
    pthread_create(&c, nullptr, ConsumerRoutine, rq);

    pthread_join(p, nullptr);
    pthread_join(c, nullptr);
    delete rq;
}

int main()
{
    srand((unsigned int)time(0) ^ getpid() ^ pthread_self());
    test1();
    return 0;
}